#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char *argv[])
{
    void *handle;
    double (*func)(double);
    char *error;

    if (argc < 3) {
        printf("usage: %s <lib> <func>\n", argv[0]);
        return -1;
    }

    handle = dlopen(argv[1], RTLD_NOW);
    if (handle == NULL) {
        printf("Open library %s error: %s\n", argv[1], dlerror());
        return -1;
    }

    func = dlsym(handle, argv[2]);
    if ((error = dlerror()) != NULL) {
        printf("Symbole %s not found: %s\n", argv[2], error);
        dlclose(handle);
        return -1;
    }

    double val = 9.0;
    printf("%s(%f) = %f\n", argv[2], val, func(val));

    dlclose(handle);
    return 0;
}
